package nio.zero_copy;

import java.io.DataOutputStream;
import java.io.FileInputStream;
import java.io.IOException;
import java.net.Socket;

public class JavaIOCopyClient {
    public static void main(String[] args) throws IOException {
        String fileName = "D:\\java-ee\\java-ee\\netty\\src\\main\\java\\nio\\zero_copy\\protoc-22.1-win64.zip";
        Socket socket = new Socket("localhost", 9001);
        DataOutputStream dataOutputStream = new DataOutputStream(socket.getOutputStream());
        FileInputStream fileInputStream = new FileInputStream(fileName);
        byte[] buffer = new byte[4096];
        int readCount = 0;
        long transferCount = 0;
        long start = System.currentTimeMillis();
        while ((readCount = fileInputStream.read(buffer)) != -1) {
            dataOutputStream.write(buffer, 0, readCount);
            transferCount += readCount;
        }
        System.out.println("传输字节数: " + transferCount + " 传输时间: " + (System.currentTimeMillis() - start));
        dataOutputStream.close();
        fileInputStream.close();
        socket.close();
    }
}
